<template>
  <section class="page">
    <headerbar>支部通知</headerbar>

    <section class="inner-content">
      <fetchData  class="detail" :loading="isLoading" :data="data"></fetchData>
      <abnormal class="detail" @refresh="loadData" v-if="abnormal"></abnormal>
      <section class="detail" v-if="data&&!isLoading">
        <h1 class="title">{{data.title}}</h1>
        <p class="date">{{getTime(data.createTime)}}</p>
        <p class="line"></p>
        <div class="cont-text">
          {{data.nodeMsg}}
        </div>
       <!-- <p class="title" style="margin-top: 20px;">附件：</p>
        <div class="text-center no-data" v-if="files.length===0">
          <img src="../../../../static/images/no_data.png" alt="">
          <p>暂无数据</p>
        </div>-->
        <ul class="list-item mui-content-padded flex-justify-start" v-if="files">
          <li class="enclosure-upload" v-for="item in files">
            <img v-if="isImage(item.fileName)" class="enclosure-upload-file" :src="item.url" @click="showImagePreview(item)"/>
            <img v-if="!isImage(item.fileName)" class="enclosure-upload-file" src="../../../../static/images/up_document.png" @click="downLoadFile(item)" />
            <p class="mui-ellipsis">{{item.fileName}}</p>
          </li>
        </ul>
      </section>
    </section>
  </section>
</template>

<script>
  import tools from '@/utils/tools'
  import api from '@/common/config/api'
  import loginService from '@/service/loginService'
  import moment from 'moment'

  export default {
    name: 'noticeNotice',
    data () {
      return {
        isLoading: true,
        abnormal: false,
        fn: tools,
        data: {},
        msgId: '',
        files: [],
        attachmentList: []
      }
    },
    created () {
      this.msgId = this.$route.params.msgId
      this.loadData()
    },
    methods: {
      loadData () {
        this.abnormal = false
        this.isLoading = true
        let data = {
          loginId: '3750',
          nodeId: this.msgId
        }
        this.fetchService.branchNodeDetail(data).then(res => {
          if (res.code !== 0) {
            if (res.code == 444) {
              this.abnormal = true
            } else {
              return tools.tip(res.message)
            }
          }
          this.isLoading = false
          this.data = res.data
          this.files = this.data.annexList || []
          console.log('---------this.data.annexList=', this.data.annexList.length)
        })
      },
      getTime (createTime) {
        return moment(createTime).format('YYYY年MM月DD日')
      },
      showImg (fileId) {
        let fileUrl = this.tools.getImgUrl(fileId)
        console.log('-------------fileUrl=', fileUrl)
        return fileUrl
      },
      go () {
        this.$router.push({path: `/feedback/${this.data.id}`})
      },
      isImage (fileName) {
        let arrExt = fileName.split('.')
        return 'PNG,JPG,JPEG,BMP,GIF'.split(',').indexOf(arrExt[arrExt.length - 1].toUpperCase()) > -1
      },
      downLoadFile (item) {
        console.log("item={}", item)
        let url = this.tools.getImgUrl(item.fileId)
        if (window.android && window.android.downloadFile) {
          window.android.downloadFile(url, item.fileName)
        }
      },
      showImagePreview (item) {
        if (item.fileId.length < 1) {
          return false
        }
        let fileUrl = this.tools.getImgUrl( item.fileId)
        item.url = fileUrl
        let imgs = [fileUrl]
        this.$createImagePreview({
          initialIndex: 0,
          imgs: imgs
        }, (h) => {
          return h('div', {
            class: {
              'image-preview-custom-header': false
            },
            slot: 'header'
          }, '')
        }).show()
      },
      showDialog () {
        let me = this
        this.$createDialog({
          type: 'confirm',
          icon: '',
          title: '温馨提示',
          content: '该通知需要反馈给发送方信息',
          confirmBtn: {
            text: '反馈',
            active: true,
            disabled: false,
            href: 'javascript:;'
          },
          onConfirm: () => {
            me.goFeedback()
          }
        }).show()
      },
      goFeedback () {
        this.go()
      },
      saveSpaceInfoRead () {
        let data = {
          loginId: '112029',
          spaceId: this.id
        }
        this.fetchService.saveSpaceInfoRead(data).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message)
          }
        })
      },
    }
  }
</script>

<style scoped>

</style>
